<?php

namespace Fin;

use C\L\AdmController;

class FundsController extends AdmController
{
    protected function init()
    {
        $this->service = $this->s_funds;

        $this->keyworkSearchKeys = [
        'uid',
        ];
        $this->hideKeys = [
        'is_delete'
        ];

        $this->timeToDateKeys = [
        'uptime', 'addtime'
        ];

        $this->updateKeys = [
        'status'
        ];

        $this->pubSearchKeys = [
        'type', 'stype'
        ];
    }

    protected function afterSearch(&$data)
    {
        $data['config'] = $this->s_funds->getStatusConfig();
        $data['config']['vip'] = $this->s_level->searchAll();
        foreach ($data['list'] as &$item) {
            $user = $this->s_user->search($item['uid']);
            $item['name'] = $user['name'] ?? '用户不存在';
            $item['mobile'] = $user['mobile'] ?? '';
            $item['note'] = $user['note'] ?? '';
        }

        $this->params['data']['btype'] = 'add';
        $data['sum_add_money'] = $this->s_funds->getSum('money', $this->params['data'], $this->params['data_type']);
        $this->params['data']['btype'] = 'sub';
        $data['sum_sub_money'] = $this->s_funds->getSum('money', $this->params['data'], $this->params['data_type']);
        return true;
    }
}
